﻿using System;
using System.IO;
using BattleNet.DataAccess.SourceProviders.Web;
using BattleNet.DataAccess.UnitTests.Providers.Web;
using Xunit;
using System.Net;
using FakeItEasy;
namespace BattleNet.DataAccess.UnitTests.Providers.Html
{
    public class WebSourceProviderTest
    {
        public WebSourceProviderTest()
        {
            WebRequest.RegisterPrefix("test", new TestWebRequestCreate());            
        }
       [Fact]
       public void Provide_RecievesInvalidUriString_ThrowsException()
       {           
           WebSourceProvider provider = new WebSourceProvider("test://doesntexist.com");                      
           Assert.Throws<WebException>( ()=> provider.Provide());
       }

       [Fact]
       public void Provide_RecievesInvalidUri_ThrowsException()
       {
           WebSourceProvider provider = new WebSourceProvider(WebRequest.Create("test://doesntexist.com"));
           Assert.Throws<WebException>(() => provider.Provide());
       }

        [Fact]
       public void Provide_RecievesValidUriString_ReturnsSource()
       {
           WebSourceProvider provider = new WebSourceProvider("test://exists.com");
           string source = Assert.IsType<string>(provider.Provide());
           Assert.Equal("Source", source);           
       }

       [Fact]
       public void Provide_RecievesValidUri_ReturnsSource()
       {

           WebSourceProvider provider = new WebSourceProvider(WebRequest.Create("test://exists.com"));
           string source = Assert.IsType<string>(provider.Provide());
           Assert.Equal("Source", source);
       }    
    }


    

   
}
